//============================================================================
// Copyright (C) 2003-2013 Brett R. Jones 
//
// Issued to public domain 2013
//
// brettjones1900@gmail.com
// http://www.p2panarchy.com
//============================================================================

#include "VxNetLib.h"

//============================================================================
//=== constructor ===//
VxSktThrottle::VxSktThrottle()
	: m_bEnableThrottle( false )
	, m_f32TxSpeedLimit( 0.0f ) 
	, m_f32RxSpeedLimit( 0.0f ) 
{
	ResetStatistics();
}

//============================================================================
//=== destructor ===//
VxSktThrottle::~VxSktThrottle()
{

}

//============================================================================
//! reset all statistics
void VxSktThrottle::ResetStatistics( void )
{
	ResetRxStatistics();
	ResetTxStatistics();
}

//============================================================================
//! reset just tx statistics
void VxSktThrottle::ResetTxStatistics( void )
{
	m_iTxSamplesCnt = 0;
	m_iTxSamplesBytes = 0;
	m_s64BytesTxed = 0;
	m_s64TxPktsDropped = 0;
	m_s64TxPktCnt = 0;
	m_f32TxCurrentSpeed = 0.0f; 
	m_oTxTimer.StartTimer();
}

//============================================================================
//! reset just send statistics
void VxSktThrottle::ResetRxStatistics( void )
{
	m_iRxSamplesCnt = 0;
	m_iTxSamplesBytes = 0;
	m_s64BytesRxed = 0;
	m_s64RxPktsDropped = 0;
	m_s64RxPktCnt = 0;
	m_f32TxCurrentSpeed = 0.0f; 
	m_oRxTimer.StartTimer();
}

//============================================================================
//! packet was sent
void VxSktThrottle::TxedPkt( int iPktLen )
{
	vx_assert( iPktLen >= 0 );
	m_s64BytesTxed += iPktLen;
	m_iTxSamplesBytes += iPktLen;
	m_iTxSamplesCnt++;
	if( VXSKT_INFO_SAMPLE_CNT == m_iTxSamplesCnt )
	{
		// compute speed
		UpdateTxSpeed();
		// reset sample info
		m_iTxSamplesBytes = 0;
		m_iTxSamplesCnt = 0;
		m_oTxTimer.StartTimer();
	}
}

//============================================================================
//! packet was recieved
void VxSktThrottle::RxedPkt( int iPktLen )
{
	m_s64BytesRxed += iPktLen;
}

//============================================================================
//! packet could not be sent
void VxSktThrottle::DroppedTxedPkt( int iPktLen )
{
}

//============================================================================
//! packet could not be recieved
void VxSktThrottle::DroppedRxedPkt( int iPktLen )
{
}
